package com.esri.core.internal.catalog;

import com.esri.core.internal.catalog.Item;
import com.esri.core.internal.io.handler.h;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import org.achartengine.internal.a;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class Group implements PageableResultType {
    private String a;
    private String b;
    private boolean c;
    private boolean d;
    private boolean e;
    private String f;
    private String g;
    private List<String> h;
    private String i;
    private String j;
    private String k;
    private byte[] l;
    private Date m;
    private Date n;
    private Catalog o;
    private String p;
    private User q;
    private List<User> r;
    private List<User> s;

    /* loaded from: classes.dex */
    public enum SortField {
        TITLE { // from class: com.esri.core.internal.catalog.Group.SortField.1
            @Override // java.lang.Enum
            public String toString() {
                return a.b;
            }
        },
        OWNER { // from class: com.esri.core.internal.catalog.Group.SortField.2
            @Override // java.lang.Enum
            public String toString() {
                return "owner";
            }
        },
        CREATED { // from class: com.esri.core.internal.catalog.Group.SortField.3
            @Override // java.lang.Enum
            public String toString() {
                return "created";
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void testAndSetOwner(User user) {
        if (user.getUserName().equals(this.p)) {
            this.q = user;
        }
    }

    public User getOwner() {
        if (this.q == null) {
            this.q = a(this.p);
        }
        return this.q;
    }

    public List<User> getAdmins() {
        if (this.r == null) {
            a();
        }
        return this.r;
    }

    public List<User> getMembers() {
        if (this.s == null) {
            a();
        }
        return this.s;
    }

    private User a(String str) {
        HashMap hashMap;
        try {
            if (this.o.getUserToken() != null) {
                hashMap = new HashMap();
                hashMap.put("token", this.o.getUserToken());
            } else {
                hashMap = null;
            }
            JsonParser a = h.a(this.o.getUrl() + "/sharing/community/users/" + str, hashMap);
            User user = new User();
            user.fromJson(a, null, this.o);
            return user;
        } catch (Exception unused) {
            return null;
        }
    }

    private void a() {
        HashMap hashMap = null;
        try {
            if (this.o.getUserToken() != null) {
                hashMap = new HashMap();
                hashMap.put("token", this.o.getUserToken());
            }
            JsonParser a = h.a(this.o.getUrl() + "/sharing/community/groups/" + this.a + "/users", hashMap);
            ArrayList<String> arrayList = new ArrayList();
            ArrayList<String> arrayList2 = new ArrayList();
            while (a.nextToken() != JsonToken.END_OBJECT) {
                String currentName = a.getCurrentName();
                a.nextToken();
                if (currentName.equals("owner")) {
                    this.p = a.getText();
                } else if (currentName.equals("admins")) {
                    while (a.nextToken() != JsonToken.END_ARRAY) {
                        arrayList.add(a.getText());
                    }
                } else if (currentName.equals("users")) {
                    while (a.nextToken() != JsonToken.END_ARRAY) {
                        arrayList2.add(a.getText());
                    }
                }
            }
            this.r = new ArrayList();
            this.s = new ArrayList();
            for (String str : arrayList) {
                User a2 = a(str);
                if (a2 != null) {
                    this.r.add(a2);
                }
            }
            for (String str2 : arrayList2) {
                User a3 = a(str2);
                if (a3 != null) {
                    this.s.add(a3);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String getId() {
        return this.a;
    }

    public String getTitle() {
        return this.b;
    }

    public boolean isOrganization() {
        return this.c;
    }

    public boolean isPublic() {
        return this.d;
    }

    public boolean isInvitationOnly() {
        return this.e;
    }

    public String getDescription() {
        return this.f;
    }

    public String getSnippet() {
        return this.g;
    }

    public List<String> getTags() {
        return this.h;
    }

    public String getPhone() {
        return this.i;
    }

    public String getFeaturedItemId() {
        return this.j;
    }

    public byte[] getThumbnail() {
        try {
            if (this.l == null) {
                String str = this.o.getUrl() + "/sharing/community/groups/" + this.a + "/info/" + this.k;
                HashMap hashMap = new HashMap();
                if (this.o.getUserToken() != null) {
                    hashMap = new HashMap();
                    hashMap.put("token", this.o.getUserToken());
                }
                this.l = com.esri.core.internal.io.handler.a.a(str, hashMap);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this.l;
    }

    public Date getCreatedDate() {
        return this.m;
    }

    public ResultCursor<Item> getItems(Item.ItemType itemType) throws CatalogException {
        String str = this.o.getUrl() + "/sharing/search";
        HashMap hashMap = new HashMap();
        try {
            if (this.o.getUserToken() != null) {
                hashMap.put("token", this.o.getUserToken());
            }
            String str2 = "group:" + this.a + " AND itemtype:\"text\"";
            if (itemType != null) {
                if (itemType == Item.ItemType.WEB_MAP) {
                    str2 = str2 + " AND type:(+\"web map\" -\"feature collection\"";
                } else if (itemType == Item.ItemType.FEATURE_COLLECTION) {
                    str2 = str2 + " AND type:(+\"feature collection\" -\"web map\"";
                }
                str2 = str2 + " -\"web mapping application\" -\"mobile application\" -\"code attachment\" -\"featured items\" -\"feature collection template\" -\"Symbol Set\")";
            }
            hashMap.put("q", str2);
            return new ResultCursor<>(this.o, str, hashMap, h.a(str, hashMap), Item.class, null);
        } catch (Exception e) {
            throw new CatalogException("Error occurred in obtaining items stored in the Group " + e.getCause());
        }
    }

    public Date getModifiedDate() {
        return this.n;
    }

    @Override // com.esri.core.internal.catalog.PageableResultType
    public boolean fromJson(JsonParser jsonParser, Filter filter, Catalog catalog) {
        if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
            return false;
        }
        this.o = catalog;
        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
            try {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if (currentName.equals("id")) {
                    this.a = jsonParser.getText();
                } else if (currentName.equals(a.b)) {
                    this.b = jsonParser.getText();
                } else if (currentName.equals("isOrganization")) {
                    this.c = jsonParser.getBooleanValue();
                } else if (currentName.equals("isPublic")) {
                    this.d = jsonParser.getBooleanValue();
                } else if (currentName.equals("isInvitationOnly")) {
                    this.e = jsonParser.getBooleanValue();
                } else if (currentName.equals("owner")) {
                    this.p = jsonParser.getText();
                } else if (currentName.equals("description")) {
                    this.f = jsonParser.getText();
                } else if (currentName.equals("snippet")) {
                    this.g = jsonParser.getText();
                } else if (currentName.equals("tags")) {
                    this.h = new ArrayList();
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        this.h.add(jsonParser.getText());
                    }
                } else if (currentName.equals("phone")) {
                    this.i = jsonParser.getText();
                } else if (currentName.equals("featuredItemsId")) {
                    this.j = jsonParser.getText();
                } else if (currentName.equals("thumbnail")) {
                    this.k = jsonParser.getText();
                } else if (currentName.equals("created")) {
                    this.m = new Date(jsonParser.getLongValue());
                } else if (currentName.equals("modified")) {
                    this.n = new Date(jsonParser.getLongValue());
                } else if (currentName.equals("userMembership")) {
                    jsonParser.skipChildren();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return true;
    }

    @Override // com.esri.core.internal.catalog.PageableResultType
    public <T extends PageableResultType> int compare(T t) {
        Group group = (Group) t;
        if (this.m.before(group.m)) {
            return -1;
        }
        return this.m.after(group.m) ? 1 : 0;
    }
}
